<?php
namespace app\admin\controller;
use app\admin\controller\Permissions;
use app\admin\model\Ewai;
use think\Config;
use \think\Db;
use \think\Cookie;
use \think\Session;
use app\admin\model\Dishang;
use app\admin\model\Gexiang;
use \think\Cache;
class Xieyi extends Permissions
{
    //地上补偿
    public function xieyi_dishang()
    {
        //$list = db('dishang')->select();

        $model = new Dishang();

        $list = $model->paginate(20);

        foreach ($list as $key => $v) {
            $poInfo = Db::name('population')->where('id',$v['uid'])->find();
            $v['name'] = $poInfo['name'];
        }
        $page = $list->render();
        $this->assign('list',$list);
        $this->assign('page', $page);

        $admin_cate_id = Session::get('admin_cate_id');
        $this->assign('admin_cate_id',$admin_cate_id);
        $operation = Config::get('operation');
        $this->assign('operation',$operation);
        return $this->fetch();
    }
       //地上补偿删除
     public function dishangdeleteData()
    {
        if (request()->isAjax()) {
            $id = input('id');
            $model = new Dishang();
            $isok = $model->where('id', $id)->delete();
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
                $arr['msg'] = "删除成功！";
            } else {
                $arr['code'] = 2;
                $arr['msg'] = "删除失败！";
            }
            return $arr;
        }
    }

    public function gexiangdeleteData()
    {
        if (request()->isAjax()) {
            $id = input('id');
            $model = new Gexiang();
            $isok = $model->where('id', $id)->delete();
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
                $arr['msg'] = "删除成功！";
            } else {
                $arr['code'] = 2;
                $arr['msg'] = "删除失败！";
            }
            return $arr;
        }
    }


    public function ewaideleteData()
    {
        if (request()->isAjax()) {
            $id = input('id');
            $model = new Ewai();
            $isok = $model->where('id', $id)->delete();
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
                $arr['msg'] = "删除成功！";
            } else {
                $arr['code'] = 2;
                $arr['msg'] = "删除失败！";
            }
            return $arr;
        }
    }

    public function xieyi_dishang_edit()
    {
        $input = input('get.');

        if (request()->isAjax()) {
            $input = input('post.');
            $id = $input['id'];
            unset($input['id']);
            $isok = db('dishang')->where(['id' =>$id])->update($input);
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
            } else {
                $arr['code'] = 2;
                $arr['msg'] = '操作失败,请刷新重试';
            }
            return $arr;
        }
        $data = db('dishang')->where(['id' => $input['id']])->find();
        $huzhu = db('population')->where(['isdel'=>1])->select();
        $this->assign('huzhu',$huzhu);
        $this->assign('data',$data);
        return $this->fetch();


    }


    public function xieyi_gexiang_edit()
    {
        $input = input('get.');

        if (request()->isAjax()) {
            $input = input('post.');
            $id = $input['id'];
            unset($input['id']);
            $isok = db('gexiang')->where(['id' =>$id])->update($input);
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
            } else {
                $arr['code'] = 2;
                $arr['msg'] = '操作失败,请刷新重试';
            }
            return $arr;
        }
        $data = db('gexiang')->where(['id' => $input['id']])->find();
        $huzhu = db('population')->where(['isdel'=>1])->select();
        $this->assign('huzhu',$huzhu);
        $this->assign('data',$data);
        return $this->fetch();


    }


    public function xieyi_ewai_edit()
    {
        $input = input('get.');

        if (request()->isAjax()) {
            $input = input('post.');
            $id = $input['id'];
            unset($input['id']);
            $isok = db('ewai')->where(['id' =>$id])->update($input);
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
            } else {
                $arr['code'] = 2;
                $arr['msg'] = '操作失败,请刷新重试';
            }
            return $arr;
        }
        $data = db('ewai')->where(['id' => $input['id']])->find();
        $huzhu = db('population')->where(['isdel'=>1])->select();
        $this->assign('huzhu',$huzhu);
        $this->assign('data',$data);
        return $this->fetch();


    }

    //地上补偿添加
    public function xieyi_dishang_add()
    {
        $huzhu = db('population')->where(['isdel'=>1])->select();
        if (request()->isAjax()) {
            $input = input('post.');
            // dump($input);die;
            $isok = db('dishang')->insert($input);
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
            } else {
                $arr['code'] = 2;
                $arr['msg'] = '操作失败,请刷新重试';
            }
            return $arr;
        }
        $this->assign('huzhu',$huzhu);
        return $this->fetch();
    }
    //各项奖励及补助
    public function xieyi_gexiang()
    {

        $model = new Gexiang();
        //$list = db('gexiang')->select();
        $list = $model->paginate(20);
        foreach ($list as $key => $v) {
            $v['name'] = db('population')->where('id',$v['uid'])->value('name');
        }
        $page = $list->render();
        $this->assign('page',$page);
        $this->assign('list',$list);

        $admin_cate_id = Session::get('admin_cate_id');
        $this->assign('admin_cate_id',$admin_cate_id);
        $operation = Config::get('operation');
        $this->assign('operation',$operation);
        return $this->fetch();
    }
    //各项奖励及补助添加
    public function xieyi_gexiang_add()
    {
        $huzhu = db('population')->where(['isdel'=>1])->select();
        if (request()->isAjax()) {
            $input = input('post.');
            // dump($input);die;
            $isok = db('gexiang')->insert($input);
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
            } else {
                $arr['code'] = 2;
                $arr['msg'] = '操作失败,请刷新重试';
            }
            return $arr;
        }
        $this->assign('huzhu',$huzhu);
        return $this->fetch();
    }
    //额外补偿明细
    public function xieyi_ewai()
    {
        //$list = db('ewai')->select();
        $model = new Ewai();
        $list = $model->paginate(20);
        foreach ($list as $key => $v) {
            $v['name'] = db('population')->where('id',$v['uid'])->value('name');
        }
        $page = $list->render();
        $this->assign('list',$list);
        $this->assign('page',$page);

        $admin_cate_id = Session::get('admin_cate_id');
        $this->assign('admin_cate_id',$admin_cate_id);
        $operation = Config::get('operation');
        $this->assign('operation',$operation);
        return $this->fetch();
    }
    
 
    
    //额外补偿明细添加
    public function xieyi_ewai_add()
    {
        $huzhu = db('population')->where(['isdel'=>1])->select();
        if (request()->isAjax()) {
            $input = input('post.');
            // dump($input);die;
            $isok = db('ewai')->insert($input);
            $arr = [];
            if ($isok) {
                $arr['code'] = 1;
            } else {
                $arr['code'] = 2;
                $arr['msg'] = '操作失败,请刷新重试';
            }
            return $arr;
        }
        $this->assign('huzhu',$huzhu);
        return $this->fetch();
    }
}
